package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dto.AllProductCateResponse;
import com.cskaoyan.shopping.dto.HomePageResponse;
import com.cskaoyan.shopping.dto.NavListResponse;
import com.cskaoyan.shopping.service.IShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cskaoyan.mall.constant.ShoppingRetCode;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Description:
 * @Author: 周佳豪
 * @Date: 2022/04/22/21:36
 */
@RestController
@RequestMapping("shopping")
public class ShoppingController {

    @Autowired
    IShoppingService shoppingService;

    @GetMapping("homepage")
    public ResponseData shoppingHomepage() {
        List<Panel> panels = shoppingService.getHomepage();

        return new ResponseUtil<>().setData(panels);
    }

    @GetMapping("navigation")
    public ResponseData shoppingNavigation() {
        NavListResponse navListResponse = shoppingService.getNavigation();
        if (ShoppingRetCode.SUCCESS.getCode().equals(navListResponse.getCode())) {
            return new ResponseUtil().setData(navListResponse.getPannelContentDtos());
        }
        return new ResponseUtil().setErrorMsg(navListResponse.getMsg());
    }

    @GetMapping("categories")
    public ResponseData shoppingCategories() {
        AllProductCateResponse allProductCateResponse = shoppingService.getAllProductCate();
        if (ShoppingRetCode.SUCCESS.getCode().equals(allProductCateResponse.getCode())) {
            return new ResponseUtil().setData(allProductCateResponse.getProductCateDtoList());
        }
        return new ResponseUtil().setErrorMsg(allProductCateResponse.getMsg());
    }


}
